package com.kuiandjie.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.kuiandjie.entity.Log;
import com.kuiandjie.util.DBHelp;
import com.kuiandjie.util.RowMapper;

public class LogDao {
	private DBHelp<Log> db = new DBHelp<Log>();
	
	private class LogMap implements RowMapper<Log>{
		@Override
		public Log mapperRow(ResultSet rs) throws SQLException {
			Log log = new Log();
			log.setId(rs.getInt("id"));
			log.setEmployeeId(rs.getInt("employeeid"));
			log.setProjectId(rs.getInt("projectid"));
			log.setDesc(rs.getString("desc"));
			log.setTime(rs.getString("time"));
			log.setPic(rs.getString("pic"));
			log.setName(rs.getString("name"));
			return log;
		}
	}

	public void setLog(Log log) {
		String sql = "INSERT INTO t_log (`desc`, employeeid, time, projectid) VALUES (?, ?, ?, ?)";
		db.executeSQL(sql, log.getDesc(), log.getEmployeeId(), log.getTime(), log.getProjectId());
	}

	public List<Log> getAllByProId(String curpid) {
		String sql = "SELECT a.id, employeeid, projectid, `desc`, `time`, b.name AS name, b.pic AS pic FROM t_log AS a, t_employee AS b WHERE a.employeeid = b.id AND a.projectid = ? ORDER BY `time` DESC";
		return db.executeQueryForList(sql, new LogMap(), curpid);
	}
	
	
}
